package ensemble;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.LinkedList;
import java.util.Scanner;

import structure.Matrice;

public class LoadData extends DataHandler{
	
	public LinkedList<Echantillon> loadData(String file) throws FileNotFoundException {
		FileReader fr= new FileReader(file);
		Scanner sc= new Scanner(fr);
		LinkedList<Echantillon> list= new LinkedList<Echantillon>();
		Echantillon e= null;
		while (sc.hasNextLine()) {
			e= createEchantillon(sc.nextLine());
			if (e!=null) list.add(e);
		}
		return list;
	}
	
	private Echantillon createEchantillon (String ligne) {
		Scanner sc= new Scanner(ligne).useDelimiter(",");
		int i=0;
		Matrice sequence= new Matrice(256, 1);
		while (sc.hasNext() && (i<256)) {
			sequence.getMatrice()[i][0]= Double.parseDouble(sc.next());
			i++;
		}
		if (i!=256) {
			return null;
		}else {
			int etiquette= Integer.parseInt(sc.next());
			return new Echantillon(sequence, etiquette);
		}
	}
}
